export default {
  namespaced:true,
  state:()=>({
    // 收获地址
    address:JSON.parse(uni.getStorageSync('address')||'{}'),
    // 登录成功之后的token字符串
    token:uni.getStorageSync('token')||'',
    // 用户信息
    userinfo:JSON.parse(uni.getStorageSync('userinfo')||'{}')
  }),
  mutations:{
    // 更新地址
    updateAddress(state,address){
      state.address=address
      this.commit('m_user/saveAddressStorage')
    },
    // 持久化存储地址
    saveAddressStorage(state){
      uni.setStorageSync('address',JSON.stringify(state.address))
    },
    // 更新用户的基本信息
    updateUserInfo(state,userinfo){
      state.userinfo=userinfo
      this.commit('m_user/saveUserInfoStorage')
    },
    // 持久化存储userinfo
    saveUserInfoStorage(state){
      uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
    },
    updateToken(state,token){
      state.token=token
      this.commit('m_user/saveTokenStorage')
    },
    saveTokenStorage(state){
      uni.setStorageSync('token',state.token)
    }
  },
  getters:{
    addstr(state) {
      if (!state.address.provinceName) return ''
      return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  }
}